package com.ruge._08_springboot_springdata_jpa.controller._02_entityManager;

import com.ruge._08_springboot_springdata_jpa.Application;
import com.ruge._08_springboot_springdata_jpa.model.base.BaseModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.util.List;

/**
 * 创建人 ：爱丽丝、如歌
 * 创建时间 ：2019-07-05  22:44
 * 描述 ：
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)//这里是启动类
public class TestSelect {
    @Autowired
    private EntityManager entityManager;

    @Test
    @Transactional
    public void testOne() {
        BaseModel userModel = entityManager.find(BaseModel.class, 15);
        System.out.println("=========查询成功========="+userModel);
    }

    @Test
    @Transactional
    public void testJPQL() {
        List userModelT = entityManager.createQuery("select t from BaseModel t ").getResultList();
        userModelT.forEach(System.out::println);
    }
}
